using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TrainTicket.VO;

namespace TrainTicket.DAO
{
    public class SeatDAO
    {
        private DbConnection _conn;
        public SeatDAO()
        {
            _conn = new DbConnection();
        }

        public DataTable GetAllSeat()
        {
            return _conn.ExecuteDataTable("sp_GetAllSeat", null);
        }

        public DataTable GetAllSeatByTrainRouter(ListTrain listTrain) 
        { 
            SqlParameter param = new SqlParameter("@ListTrainID", SqlDbType.Int);
            param.Value = listTrain.ListTrainID;
            return _conn.ExecuteDataTable("sp_GetAllSeatByListTrain", param);
        }

        public DataTable GetStatusSeat(int seatID)
        {
            SqlParameter param = new SqlParameter("@SeatID", SqlDbType.Int);
            param.Value = seatID;
            return _conn.ExecuteDataTable("sp_GetStatusSeat", param);
        }

        public DataTable GetSeatById(int seatID)
        {
            SqlParameter param = new SqlParameter("@SeatID", SqlDbType.Int);
            param.Value = seatID;
            return _conn.ExecuteDataTable("sp_GetSeatById", param);
        }

        public int CheckSeatExitsUpdate(int listTrainID, string numberSeat)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@ListTrainID", SqlDbType.Int);
            param[0].Value = listTrainID;

            param[1] = new SqlParameter("@NumberSeat", SqlDbType.NVarChar, 50);
            param[1].Value = numberSeat;

            return _conn.ExecuteScalar("sp_CheckSeatExitsUpdate", param);
        }

        public int UpdateSeat(int seatID, string numberSeat)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@SeatID", SqlDbType.Int);
            param[0].Value = seatID;

            param[1] = new SqlParameter("@NumberSeat", SqlDbType.NVarChar, 50);
            param[1].Value = numberSeat;

            return _conn.ExecuteNonQuery("sp_UpdateSeat", param);
        }

        public DataTable SearchSeat(int listTrainID, string numberSeat, string status)
        {
            SqlParameter[] param = new SqlParameter[3];

            param[0] = new SqlParameter("@ListTrainID", SqlDbType.Int);
            param[0].Value = listTrainID;

            param[1] = new SqlParameter("@NumberSeat", SqlDbType.NVarChar, 50);
            param[1].Value = numberSeat;

            param[2] = new SqlParameter("@Status", SqlDbType.NVarChar, 50);
            param[2].Value = status;

            return _conn.ExecuteDataTable("sp_SearchSeat", param);
        }
    }
}
